﻿using System;
using System.Collections.Generic;
using System.Linq;

class RemoveMinNumber
{
    static List<int> result = new List<int>();

    static void Main()
    {
        Console.Write("Number of elements of array:");
        int arrayLength = int.Parse(Console.ReadLine());
        int[] inputArray = new int[arrayLength];
        for (int i = 0; i < arrayLength; i++)
        {
            Console.Write("\nElement a[{0}]:", i);
            inputArray[i] = (int.Parse(Console.ReadLine()));
        }

        //int[] inputArray = { 2, 1, 2, 4, 3, 5, 2, 6, 9, 3, 0, 11, 50, 18 };

        int[] array = new int[inputArray.Length];

        Subset(inputArray.Length - 1, array, inputArray);

        Print(result);
    }

    static void Subset(int n, int[] subsetsArray, int[] inputArray)
    {
        if (n < 0)
        {
            StoreArrays(subsetsArray);
            return;
        }

        subsetsArray[n] = int.MinValue;
        Subset(n - 1, subsetsArray, inputArray);
        
        subsetsArray[n] = inputArray[n];
        Subset(n - 1, subsetsArray, inputArray);
    }

    static void StoreArrays(int[] array)
    {
        List<int> candidateList = new List<int>();
        for (int i = 0; i < array.Length; i++)
        {
            if (array[i] != int.MinValue)
            {
                candidateList.Add(array[i]);
            }
        }

        int previousNumber = int.MinValue;
        for (int i = 0; i < candidateList.Count; i++)
        {
            if (previousNumber > candidateList[i])
            {
                candidateList.Clear();
                break;
            }
            else
            {
                previousNumber = candidateList[i];
            }
        }
        if (result.Count < candidateList.Count)
        {
            result = candidateList;
        }
    }

    static void Print(List<int> array)
    {
        Console.WriteLine("The result after removing minimum members is:");
        for (int i = 0; i < array.Count; i++)
        {
            if (array[i] != 0)
            {
                Console.Write(" " + array[i]);
            }
        }
        Console.WriteLine();
    }
}